import asyncio
import logging

from aiohttp import web

routes = web.RouteTableDef()


@routes.get('/')  # Flask风格
async def index(req: web.Request):
    logging.info('Request: {}, match_info: {}', req.url, req.match_info)
    return web.Response(body='<h1>Hello AIOHttp</h1>')


@routes.get('/{name}')
async def hello(req: web.Request):
    logging.info('Request: {}, match_info: {}', req.url, req.match_info)
    return web.Response(body=f'<h1>Hello {req.match_info["name"]}</h1>')


if __name__ == '__main__':
    app = web.Application()
    app.add_routes([web.get('/', index), web.get('/{name}', hello)])
    web.run_app(app, host='localhost', port=24680, reuse_address=True)